package com.LeeCode;

/**
 * 替换一个数字后的最大差值
 */

public class Code2566 {
    public static void main(String[] args) {
        int num = 9999;
        System.out.println(new Code2566().minMaxDifference(num));
    }

    public int minMaxDifference(int num) {
        String numStr = String.valueOf(num);

        int maxNum = num;
        for (char c : numStr.toCharArray()) {
            if (c != '9') {
                maxNum = Integer.parseInt(numStr.replace(c, '9'));
                break;
            }
        }
        int minNum = Integer.parseInt(numStr.replace(numStr.charAt(0), '0'));

        return maxNum - minNum;
    }

}
